package cn.com.idmy.auth.context;


import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@AllArgsConstructor
public class StorageForServlet implements Storage {
    protected final HttpServletRequest request;

    @Override
    public @NotNull Object source() {
        return request;
    }

    @Override
    public @NotNull StorageForServlet set(@NotNull String key, @NotNull Object value) {
        request.setAttribute(key, value);
        return this;
    }

    @Override
    public @Nullable Object get(@NotNull String key) {
        return request.getAttribute(key);
    }

    @Override
    public @NotNull StorageForServlet remove(@NotNull String key) {
        request.removeAttribute(key);
        return this;
    }
}
